package com.application.lucky.activity.me;


import android.content.Intent;
import android.os.Bundle;
import android.support.v7.widget.LinearLayoutManager;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;

import com.application.lucky.R;
import com.application.lucky.activity.KeFuActivity;
import com.application.lucky.activity.PbChatActivity;
import com.application.lucky.adapter.RechargeAdapter;
import com.application.lucky.bean.jsonBean.RechargeGroup;
import com.application.lucky.bean.jsonBean.RechargeItem;
import com.application.lucky.config.Config;
import com.application.lucky.widget.TitlebarView;
import com.application.mylibrary.base.BaseActivity;
import com.chad.library.adapter.base.BaseQuickAdapter;
import com.chad.library.adapter.base.entity.MultiItemEntity;
import com.qunar.im.base.common.ConversitionType;

import java.util.ArrayList;
import java.util.List;

public class RechargeActivity extends BaseActivity {

    private TitlebarView mTitleBar;
    private RecyclerView mRclView;
    private RechargeAdapter adapter;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);

        initView();
        mTitleBar.setOnViewClick(new TitlebarView.onViewClick() {
            @Override
            public void leftClick() {
                finishAnim();
            }

            @Override
            public void rightClick() {

            }
        });

        loadData();
    }

    int[] iconRes = {R.drawable.icon_recharge_zfb, R.drawable.icon_recharge_wx, R.drawable.icon_recharge_gf};
    String[] titleRes = {"支付宝", "微信", "官方"};

    private void loadData() {
        List<MultiItemEntity> datas = new ArrayList<>();
        for (int i = 0; i < 3; i++) {
            RechargeGroup level0 = RechargeGroup.getLevel0();
            level0.title = titleRes[i];
            level0.iconRes = iconRes[i];
            RechargeItem level1 = new RechargeItem();
            level1.content = "sdlkjasdlk";
            level1.title = titleRes[i];
            level0.addSubItem(level1);
            datas.add(level0);
        }
        adapter.setNewData(datas);
        adapter.addFooterView(getfootView());
    }

    private View getfootView() {
        View view = LayoutInflater.from(this).inflate(R.layout.view_recharge_foot, null);
        view.findViewById(R.id.tv_recharge_kefu).setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                Intent intent = new Intent(RechargeActivity.this, PbChatActivity.class);
                intent.putExtra(PbChatActivity.KEY_JID, Config.IMIdUtils.getIMUid(Config.KEFU_ID));
                intent.putExtra(PbChatActivity.KEY_CHAT_TYPE, String.valueOf(ConversitionType.MSG_TYPE_CHAT));
                intent.putExtra(PbChatActivity.KEY_IS_CHATROOM, false);
                startActivity(intent);
//                startActivityAnim(new Intent(RechargeActivity.this, KeFuActivity.class));
            }
        });
        return view;
    }


    @Override
    public void beforeInit() {

    }

    @Override
    public int getLayoutId() {
        return (R.layout.activity_recharge);
    }


    private void initView() {
        mTitleBar = (TitlebarView) findViewById(R.id.title_bar);
        mRclView = (RecyclerView) findViewById(R.id.rcl_view);
        mRclView.setLayoutManager(new LinearLayoutManager(this));
        adapter = new RechargeAdapter(new ArrayList<MultiItemEntity>());
        mRclView.setAdapter(adapter);
        adapter.setOnItemClickListener(new BaseQuickAdapter.OnItemClickListener() {
            @Override
            public void onItemClick(BaseQuickAdapter adapter, View view, int position) {
                MultiItemEntity item1 = RechargeActivity.this.adapter.getItem(position);
                if (item1 instanceof RechargeItem) {
                    RechargeItem item = (RechargeItem) RechargeActivity.this.adapter.getItem(position);
                    if (item != null) {

                        Intent intent = new Intent(RechargeActivity.this, ToRechargeActivity.class);
                        intent.putExtra("channel", item.title);
                        intent.putExtra("channel_name", item.content);
                        startActivityAnim(intent);

                    }
                }

            }
        });
    }
}
